<?php
namespace app\index\controller;

use think\Controller;

class Index extends Controller
{
    public function index()
    {
        $path = 'F:/wamp64/www/thinkphp/application'; //你想要哪个文件夹下面的注释生成对应的API文档
        $swagger = \Swagger\scan($path);
        // header('Content-Type: application/json');
        // echo $swagger;
        $swagger_json_path = 'F:/wamp64/www/thinkphp/public/swaggerApi/swagger.json';
        $res = file_put_contents($swagger_json_path, $swagger);
        if ($res == true) {
            $this->redirect('http://localhost/thinkphp/public/index.html');
        }

        /*$path = APP_PATH; //你想要哪个文件夹下面的注释生成对应的API文档
        $swagger = \Swagger\scan($path);
        // header('Content-Type: application/json');
        // echo $swagger;
        $swagger_json_path = ROOT_PATH.'public/swaggerApi/swagger.json';
        // 检测模板目录
        $dir = dirname($swagger_json_path);
        if (!is_dir($dir)) {
            mkdir($dir, 0755, true);
        }

        $myfile = fopen($swagger_json_path, "w") or die("Unable to open file!");
        $swagger=json_encode($swagger, true);
        fwrite($myfile, $swagger);
        fclose($myfile);*/
    }

}